package com.aaa.jx.service.impl;

import com.aaa.jx.entity.TabUser;
import com.aaa.jx.dao.TabUserDao;
import com.aaa.jx.service.TabUserService;
/**
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
*/
import com.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;
import javax.annotation.Resource;
import java.util.List;

/**
 * (TabUser)表服务实现类
 *
 * @author makejava
 * @since 2023-04-26 17:03:31
 */
//@Service("tabUserService")
public class TabUserServiceImpl implements TabUserService {
/**
    @Resource
    private TabUserDao tabUserDao;
*/
    SqlSession session= SqlSessionFactoryUtil.getSession();
    TabUserDao tabUserDao= session.getMapper(TabUserDao.class);

    @Override
    public long count(TabUser tabUser) {
        return this.tabUserDao.count(tabUser);
    }

    @Override
    public List<TabUser> queryAll(TabUser tabUser) {
        return this.tabUserDao.queryAllByLimit(tabUser);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public TabUser queryById(Integer id) {
        return this.tabUserDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param tabUser 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
     /**
    @Override
    public Page<TabUser> queryByPage(TabUser tabUser, PageRequest pageRequest) {
        long total = this.tabUserDao.count(tabUser);
        return new PageImpl<>(this.tabUserDao.queryAllByLimit(tabUser, pageRequest), pageRequest, total);
    }*/

    /**
     * 新增数据
     *
     * @param tabUser 实例对象
     * @return 实例对象
     */
    @Override
    public TabUser insert(TabUser tabUser) {
        this.tabUserDao.insert(tabUser);
        return tabUser;
    }

    /**
     * 修改数据
     *
     * @param tabUser 实例对象
     * @return 实例对象
     */
    @Override
    public TabUser update(TabUser tabUser) {
        this.tabUserDao.update(tabUser);
        return this.queryById(tabUser.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.tabUserDao.deleteById(id) > 0;
    }
}
